home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / ka9q / kit_src / mk_auto.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-03  |  12.6 KB  |  351 lines

  1. /*    (C) Copyright 1991 Dave Fritsche (wb8zxu), All Rights Reserved.
  2.  * 
  3.  *    Redistribution and use in source and binary forms are permitted for
  4.  *    non-commercial use, provided that the above copyright notice and this
  5.  *    paragraph are duplicated in all such forms.  THIS SOFTWARE IS PROVIDED
  6.  *    ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
  7.  *    WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND
  8.  *    FITNESS FOR A PARTICULAR PURPOSE.
  9.  */
  10. #include <stdio.h>
  11. #include "screen.h"
  12.  
  13. mk_auto(fnm)
  14. unsigned char fnm[];
  15. {
  16.     FILE *aexec;
  17.     unsigned char buf[128], defrou[5], tmp[10];
  18.  
  19.     if ( (path[strlen(path)-1] == '/') || (path[strlen(path)-1] == '\\') )
  20.         path[strlen(path)-1] = NULL;
  21.     sprintf(buf, "%s\\%s", path, fnm);
  22.     if (debug)
  23.     {
  24.         printf("***> autoexec.net file (%s):\n", buf);
  25.         aexec = stdout;
  26.     }
  27.     else
  28.     {
  29.         if ( (aexec = fopen(buf, "r")) != NULL )
  30.         {
  31.             printf("\n(%s) already exists, overwrite (y/n)?  ",buf);
  32.             scanf("%s", tmp);
  33.             if ( (tmp[0] != 'y') && (tmp[0] != 'Y') )
  34.             {
  35.                 fclose(aexec);
  36.                 return 0;
  37.             }
  38.         }
  39.         fclose(aexec);
  40.         if ( (aexec = fopen(buf, "w")) == NULL )
  41.         {
  42.             printf("\nCan't open \"%s\" for write, aborting!\n\n", buf);
  43.             exit(-1);
  44.         }
  45.     }
  46.  
  47.     if (g1emm)
  48.         fprintf(aexec, "#  A U T O E X E C . N E T     F O R     N O S     ( G 1 E M M )\n");
  49.     else
  50.         fprintf(aexec, "#  A U T O E X E C . N E T     F O R     N O S\n");
  51.     fprintf(aexec, "# ===========================================================================\n");
  52.     fprintf(aexec, "#      Local Definitions\n");
  53.     fprintf(aexec, "# ===========================================================================\n");
  54.     fprintf(aexec, "hostname %s\n", callsign);
  55.     fprintf(aexec, "ax25 mycall %s\n", callsign);
  56.     fprintf(aexec, "ip address %s\n", callsign);
  57.     fprintf(aexec, "# ===========================================================================\n");
  58.     fprintf(aexec, "#      Attach ports\n");
  59.     fprintf(aexec, "# ===========================================================================\n");
  60.     if (com1)
  61.     {
  62.         fprintf(aexec, "# COM1: SET UP AS A %ld bps CONNECTION\n",com1spd);
  63.         fprintf(aexec, "attach asy 0x3f8 4 %s ax1 2048 256 %ld\n", com1typ, com1spd);
  64.     }
  65.     if (com2)
  66.     {
  67.         fprintf(aexec, "# COM2: SET UP AS A %ld bps CONNECTION\n",com2spd);
  68.         fprintf(aexec, "attach asy 0x2f8 3 %s ax2 2048 256 %ld\n", com2typ, com2spd);
  69.     }
  70.     if (com3)
  71.     {
  72.         fprintf(aexec, "# COM3: SET UP AS A %ld bps CONNECTION\n",com3spd);
  73.         fprintf(aexec, "attach asy 0x3e8 4 %s ax3 2048 256 %ld\n", com3typ, com3spd);
  74.     }
  75.     if (com4)
  76.     {
  77.         fprintf(aexec, "# COM4: SET UP AS A %ld bps CONNECTION\n",com4spd);
  78.         fprintf(aexec, "attach asy 0x2e8 3 %s ax4 2048 256 %ld\n", com4typ, com4spd);
  79.     }
  80.     if (drsi_0 && !drsi_1)
  81.     {
  82.         fprintf(aexec, "# DRSI first port only init\n");
  83.         fprintf(aexec, "attach scc 1 init 300 16 2 0 1 0 7 p4915200 8\n");
  84.         fprintf(aexec, "attach scc 0 %s da0 256 d%ld 1024 %s\n", drsi_0typ, drsi_0spd, callsign);
  85.     }
  86.     if (!drsi_0 && drsi_1)
  87.     {
  88.         fprintf(aexec, "# DRSI second port only init\n");
  89.         fprintf(aexec, "attach scc 1 init 300 16 2 0 1 0 7 p4915200 8\n");
  90.         fprintf(aexec, "attach scc 1 %s da1 256 d%ld 1024 %s\n", drsi_1typ, drsi_1spd, callsign);
  91.     }
  92.     if (drsi_0 && drsi_1)
  93.     {
  94.         fprintf(aexec, "# DRSI two port init\n");
  95.         fprintf(aexec, "attach scc 2 init 300 16 2 0 1 0 7 p4915200 8\n");
  96.         fprintf(aexec, "attach scc 0 %s da0 256 d%ld 1024 %s\n", drsi_0typ, drsi_0spd, callsign);
  97.         fprintf(aexec, "attach scc 1 %s da1 256 d%ld 1024 %s\n", drsi_1typ, drsi_1spd, callsign);
  98.     }
  99.     if (pc100_0 && !pc100_1)
  100.     {
  101.         fprintf(aexec, "# PC100-series first port only init\n");
  102.         fprintf(aexec, "attach scc 1 init 220 16 6 4 1 0 2 p4915200 2 02\n");
  103.         fprintf(aexec, "attach scc 0 %s pa0 256 d%ld 1024 %s\n", pc100_0typ, pc100_0spd, callsign);
  104.     }
  105.     if (!pc100_0 && pc100_1)
  106.     {
  107.         fprintf(aexec, "# PC100-series second port only init\n");
  108.         fprintf(aexec, "attach scc 1 init 220 16 6 4 1 0 2 p4915200 2 02\n");
  109.         fprintf(aexec, "attach scc 1 %s pa1 256 d%ld 1024 %s\n", pc100_1typ, pc100_1spd, callsign);
  110.     }
  111.     if (pc100_0 && pc100_1)
  112.     {
  113.         fprintf(aexec, "# PC100-series two port init\n");
  114.         fprintf(aexec, "attach scc 2 init 220 16 6 4 1 0 2 p4915200 2 02\n");
  115.         fprintf(aexec, "attach scc 0 %s pa0 256 d%ld 1024 %s\n", pc100_0typ, pc100_0spd, callsign);
  116.         fprintf(aexec, "attach scc 1 %s pa1 256 d%ld 1024 %s\n", pc100_1typ, pc100_1spd, callsign);
  117.     }
  118.     fprintf(aexec, "# ===========================================================================\n");
  119.     fprintf(aexec, "#     Set comm parameters\n");
  120.     fprintf(aexec, "# ===========================================================================\n");
  121.     fprintf(aexec, "# <KISS param 1> = TX Delay (10mS units):\n");
  122.     fprintf(aexec, "# <KISS param 2> = Persist (1/256th units):\n");
  123.     fprintf(aexec, "# <KISS param 3> = Slot time (10mS units):\n");
  124.     fprintf(aexec, "# <KISS param 4> = TX-tail Delay (10mS units):\n");
  125.     fprintf(aexec, "# <KISS param 5> = Duplex (0=half, 1=full):\n");
  126.     if (com1)
  127.     {
  128.         if ( ((com1typ[0] == 'a') || (com1typ[0] == 'A'))
  129.           && ((com1typ[1] == 'x') || (com1typ[1] == 'X'))
  130.           && (com1typ[2] == '2') && (com1typ[3] == '5') )
  131.         {
  132.             fprintf(aexec, "param ax1 1 45\n");
  133.             fprintf(aexec, "param ax1 2 33\n");
  134.             fprintf(aexec, "param ax1 3 18\n");
  135.             fprintf(aexec, "param ax1 4 20\n");
  136.             fprintf(aexec, "param ax1 5 0\n");
  137.         }
  138.         fprintf(aexec, "mode ax1 datagram\n");
  139.     }
  140.     if (com2)
  141.     {
  142.         if ( ((com2typ[0] == 'a') || (com2typ[0] == 'A'))
  143.           && ((com2typ[1] == 'x') || (com2typ[1] == 'X'))
  144.           && (com2typ[2] == '2') && (com2typ[3] == '5') )
  145.         {
  146.             fprintf(aexec, "param ax2 1 45\n");
  147.             fprintf(aexec, "param ax2 2 33\n");
  148.             fprintf(aexec, "param ax2 3 18\n");
  149.             fprintf(aexec, "param ax2 4 20\n");
  150.             fprintf(aexec, "param ax2 5 0\n");
  151.         }
  152.         fprintf(aexec, "mode ax2 datagram\n");
  153.     }
  154.     if (com3)
  155.     {
  156.         if ( ((com3typ[0] == 'a') || (com3typ[0] == 'A'))
  157.           && ((com3typ[1] == 'x') || (com3typ[1] == 'X'))
  158.           && (com3typ[2] == '2') && (com3typ[3] == '5') )
  159.         {
  160.             fprintf(aexec, "param ax3 1 45\n");
  161.             fprintf(aexec, "param ax3 2 33\n");
  162.             fprintf(aexec, "param ax3 3 18\n");
  163.             fprintf(aexec, "param ax3 4 20\n");
  164.             fprintf(aexec, "param ax3 5 0\n");
  165.         }
  166.         fprintf(aexec, "mode ax3 datagram\n");
  167.     }
  168.     if (com4)
  169.     {
  170.         if ( ((com4typ[0] == 'a') || (com4typ[0] == 'A'))
  171.           && ((com4typ[1] == 'x') || (com4typ[1] == 'X'))
  172.           && (com4typ[2] == '2') && (com4typ[3] == '5') )
  173.         {
  174.             fprintf(aexec, "param ax4 1 45\n");
  175.             fprintf(aexec, "param ax4 2 33\n");
  176.             fprintf(aexec, "param ax4 3 18\n");
  177.             fprintf(aexec, "param ax4 4 20\n");
  178.             fprintf(aexec, "param ax4 5 0\n");
  179.         }
  180.         fprintf(aexec, "mode ax4 datagram\n");
  181.     }
  182.     if (drsi_0)
  183.         fprintf(aexec, "mode da0 datagram\n");
  184.     if (drsi_1)
  185.         fprintf(aexec, "mode da1 datagram\n");
  186.     if (pc100_0)
  187.         fprintf(aexec, "mode pa0 datagram\n");
  188.     if (pc100_1)
  189.         fprintf(aexec, "mode pa1 datagram\n");
  190.     fprintf(aexec, "ip ttl 16\n");
  191.     fprintf(aexec, "tcp mss 216\n");
  192.     fprintf(aexec, "tcp window 216\n");
  193.     fprintf(aexec, "tcp irtt 30000\n");
  194.     fprintf(aexec, "ax25 paclen 256\n");
  195.     fprintf(aexec, "ax25 window 256\n");
  196.     fprintf(aexec, "ax25 digipeat on\n");
  197.     fprintf(aexec, "ax25 maxframe 1\n");
  198.     fprintf(aexec, "ax25 retry 5\n");
  199.     fprintf(aexec, "ax25 irtt 5000\n");
  200.     fprintf(aexec, "ax25 blimit 7\n");
  201.     fprintf(aexec, "ax25 version 2\n");
  202.     fprintf(aexec, "# ===========================================================================\n");
  203.     fprintf(aexec, "#     Start Servers\n");
  204.     fprintf(aexec, "# ===========================================================================\n");
  205.     fprintf(aexec, "start ax25\n");
  206.     if (nr_rqd)
  207.         fprintf(aexec, "start netrom\n");
  208.     fprintf(aexec, "start ttylink\n");
  209.     fprintf(aexec, "start echo\n");
  210.     fprintf(aexec, "start discard\n");
  211.     fprintf(aexec, "start telnet\n");
  212.     fprintf(aexec, "start ftp\n");
  213.     fprintf(aexec, "start smtp\n");
  214.     fprintf(aexec, "start finger\n");
  215.     fprintf(aexec, "start remote\n");
  216.     if (nr_rqd)
  217.     {
  218.         fprintf(aexec, "# ===========================================================================\n");
  219.         fprintf(aexec, "#     Netrom\n");
  220.         fprintf(aexec, "# ===========================================================================\n");
  221.         fprintf(aexec, "attach netrom\n");
  222.         sprintf(buf, "%2.2lx%2.2lx%2.2lx", ((ip >> 16) & 0xff),
  223.                     ((ip >> 8) & 0xff), (ip & 0xff) );
  224.         buf[0] = (unsigned char)toupper( (unsigned int)buf[0] );
  225.         buf[1] = (unsigned char)toupper( (unsigned int)buf[1] );
  226.         buf[2] = (unsigned char)toupper( (unsigned int)buf[2] );
  227.         buf[3] = (unsigned char)toupper( (unsigned int)buf[3] );
  228.         buf[4] = (unsigned char)toupper( (unsigned int)buf[4] );
  229.         buf[5] = (unsigned char)toupper( (unsigned int)buf[5] );
  230.         fprintf(aexec, "netrom nodetimer 1200\n");
  231.         fprintf(aexec, "netrom obsotimer 3600\n");
  232.         fprintf(aexec, "netrom ttl 15\n");
  233.         fprintf(aexec, "netrom retries 5\n");
  234.         fprintf(aexec, "netrom irtt 30000\n");
  235.         fprintf(aexec, "netrom window 1\n");
  236.         fprintf(aexec, "netrom verbose no\n");
  237.         fprintf(aexec, "mode netrom vc\n");
  238.         if (com1)
  239.         {
  240.             fprintf(aexec, "netrom interface ax1 %s 255\n", buf);
  241.             fprintf(aexec, "netrom bcnodes ax1\n");
  242.         }
  243.         if (com2)
  244.         {
  245.             fprintf(aexec, "netrom interface ax2 %s 255\n", buf);
  246.             fprintf(aexec, "netrom bcnodes ax2\n");
  247.         }
  248.         if (com3)
  249.         {
  250.             fprintf(aexec, "netrom interface ax3 %s 255\n", buf);
  251.             fprintf(aexec, "netrom bcnodes ax3\n");
  252.         }
  253.         if (com4)
  254.         {
  255.             fprintf(aexec, "netrom interface ax4 %s 255\n", buf);
  256.             fprintf(aexec, "netrom bcnodes ax4\n");
  257.         }
  258.         if (drsi_0)
  259.         {
  260.             fprintf(aexec, "netrom interface da0 %s 255\n", buf);
  261.             fprintf(aexec, "netrom bcnodes da0\n");
  262.         }
  263.         if (drsi_1)
  264.         {
  265.             fprintf(aexec, "netrom interface da1 %s 255\n", buf);
  266.             fprintf(aexec, "netrom bcnodes da1\n");
  267.         }
  268.         if (pc100_0)
  269.         {
  270.             fprintf(aexec, "netrom interface pa0 %s 255\n", buf);
  271.             fprintf(aexec, "netrom bcnodes pa0\n");
  272.         }
  273.         if (pc100_1)
  274.         {
  275.             fprintf(aexec, "netrom interface pa1 %s 255\n", buf);
  276.             fprintf(aexec, "netrom bcnodes pa1\n");
  277.         }
  278.     }
  279.     fprintf(aexec, "# ===========================================================================\n");
  280.     fprintf(aexec, "#     Routing\n");
  281.     fprintf(aexec, "# ===========================================================================\n");
  282.     if (com1)
  283.         strcpy(defrou, "ax1");
  284.     else if (com2)
  285.         strcpy(defrou, "ax2");
  286.     else if (com3)
  287.         strcpy(defrou, "ax3");
  288.     else if (com4)
  289.         strcpy(defrou, "ax4");
  290.     else if (drsi_0)
  291.         strcpy(defrou, "da0");
  292.     else if (drsi_1)
  293.         strcpy(defrou, "da1");
  294.     else if (pc100_0)
  295.         strcpy(defrou, "pa0");
  296.     else if (pc100_1)
  297.         strcpy(defrou, "pa1");
  298.     fprintf(aexec, "route addprivate default %s", defrou);
  299.     if (gate_rqd)
  300.         fprintf(aexec, " [%ld.%ld.%ld.%ld]\n", ((gateway >> 24) & 0xff),
  301.             ((gateway >> 16) & 0xff), ((gateway >> 8) & 0xff),
  302.             (gateway & 0xff), callsign);
  303.     else
  304.         fprintf(aexec, "\n");
  305.     if (g1emm)
  306.     {
  307.         fprintf(aexec, "# ========================================================================\n");
  308.         fprintf(aexec, "#    RSPF configuration\n");
  309.         fprintf(aexec, "# ========================================================================\n");
  310.         fprintf(aexec, "#ifconfig %s broadcast [%ld.%ld.255.255]\n",
  311.                 defrou, ((ip >> 24) & 0xff),
  312.                 ((ip >> 16) & 0xff) );
  313.         fprintf(aexec, "#rspf interface %s 8 32\n", defrou);
  314.         fprintf(aexec, "#rspf rrhtimer 1800\n");
  315.         fprintf(aexec, "#rspf suspecttimer 4000\n");
  316.         fprintf(aexec, "#rspf timer 1800\n");
  317.         fprintf(aexec, "#rspf message \"KA9Q TCP/IP RSPF Routing -- Share and Enjoy!!\"\n");
  318.     }
  319.     fprintf(aexec, "# ===========================================================================\n");
  320.     fprintf(aexec, "#     Misc\n");
  321.     fprintf(aexec, "# ===========================================================================\n");
  322.     if (g1emm)
  323.     {
  324.         fprintf(aexec, "mem eff on\n");
  325.         fprintf(aexec, "multi off\n");
  326.         fprintf(aexec, "motd \"If no one answers, escape back to the Mbox, and leave a message\"\n");
  327.         fprintf(aexec, "attend on\n");
  328.         fprintf(aexec, "tcp timer linear\n");
  329.         fprintf(aexec, "ax25 timer linear\n");
  330.         if (nr_rqd)
  331.             fprintf(aexec, "netrom timer linear\n");
  332.         fprintf(aexec, "domain cache size 15\n");
  333.         fprintf(aexec, "domain translate off\n");
  334.         fprintf(aexec, "domain verbose off\n");
  335.     }
  336.     if (rmt_pass)
  337.         fprintf(aexec, "remote -s %s\n", password);
  338.     fprintf(aexec, "log nos.log\n");
  339.     fprintf(aexec, "smtp timer 1800\n");
  340.     fprintf(aexec, "smtp trace 0\n");
  341.     fprintf(aexec, "smtp maxclients 7\n");
  342.     fprintf(aexec, "smtp batch on\n");
  343.     fprintf(aexec, "mbox motd \"IP ==> [%ld.%ld.%ld.%ld]     Leave msg using:  S %s\"\n",
  344.         ((ip >> 24) & 0xff), ((ip >> 16) & 0xff), ((ip >> 8) & 0xff),
  345.         (ip & 0xff), callsign);
  346.     fprintf(aexec, "mbox attend on\n");
  347.  
  348.     if (!debug)
  349.         fclose(aexec);
  350. }
  351.